package com.harlan.viewbindingstudy.kotlin


import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

import com.harlan.viewbindingstudy.databinding.ActivityKotlinBinding

class KotlinActivity : AppCompatActivity() {
    lateinit var binding: ActivityKotlinBinding
    lateinit var branch: BranchFragment
    var fragments = ArrayList<Fragment>()
    lateinit var blankKotlin: BlankKotlinFragment
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityKotlinBinding.inflate(layoutInflater)
        setContentView(binding.root)
        blankKotlin = BlankKotlinFragment()
        branch = BranchFragment()
        fragments.add(blankKotlin)
        fragments.add(branch)
        var fm = supportFragmentManager
        var adapter = MainAdapter(fm, fragments)
        binding.viewpager.adapter = adapter
    }

    class MainAdapter : FragmentPagerAdapter {
        lateinit var fragment: List<Fragment>

        constructor(fragmentManager: FragmentManager, frag: ArrayList<Fragment>) : super(
            fragmentManager
        ) {
            this.fragment = frag
        }

        override fun getCount(): Int {
            return fragment.size
        }

        override fun getItem(position: Int): Fragment {
            return fragment[position]
        }

    }
}


